package com.zws.cucumber.util.jsonunit;

import com.zws.cucumber.expander.ZwsStr;
import com.zws.cucumber.expr.ZwsExpr;
import net.javacrumbs.jsonunit.core.ParametrizedMatcher;
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;

public class ZwsVerifierMatcher extends BaseMatcher<Object> implements ParametrizedMatcher {
    private String raw;
    @Override
    public void setParameter(String parameter) {
        this.raw = parameter.trim();
    }

    @Override
    public boolean matches(Object actual) {
        return ZwsExpr.verifySilently("verifier", ZwsStr.expand(raw), actual);
    }

    @Override
    public void describeTo(Description description) {
        description.appendText(raw);
    }

    @Override
    public void describeMismatch(Object item, Description description) {
        description.appendText("verifier evaluate [").appendText(raw).appendText("] to false");
    }
}
